package com.compass.doctor.ui.chat.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.compass.doctor.R;
import com.compass.framework.toast.TipsToast;

import com.netease.yunxin.kit.common.utils.SizeUtils;

/**
 * Description： PopItem管理
 * Date:2023/12/13 19:25
 */
public interface PopItemFactory {

    static CustomListPopView.Item getAddFriendItem(Context context) {
        LinearLayout.LayoutParams params = getParams(context);
        return new CustomListPopView.Item.Builder()
                .configView(
                        getView(context, R.string.add_patient, R.mipmap.ic_chat_add_patient))
                .configParams(params)
                .configClickListener(
                        v -> TipsToast.INSTANCE.showTips("添加患者操作"))
                .build();
    }

     static CustomListPopView.Item getDivideLineItem(Context context) {
        LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(0.5f));
        params.setMargins(SizeUtils.dp2px(16), 0, SizeUtils.dp2px(16), 0);
        return new CustomListPopView.Item.Builder()
                .configView(getDivideView(context))
                .configParams(params)
                .build();
    }

    static CustomListPopView.Item getSendMessageItem(Context context, int memberLimit) {
        LinearLayout.LayoutParams params = getParams(context);
        return new CustomListPopView.Item.Builder()
                .configView(
                        getView(
                                context, R.string.send_mass_message, R.mipmap.ic_chat_send_mass_message))
                .configParams(params)
                .configClickListener(
                        v -> TipsToast.INSTANCE.showTips("群发消息界面"))
                .build();
    }

     static View getDivideView(Context context) {
        View view = new View(context);
        view.setBackgroundResource(R.color.color_d6d6d6);
        return view;
    }

    static View getView(Context context, int txtId, int drawableId) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER_VERTICAL);
        textView.setTextSize(14);
        textView.setMaxLines(1);
        textView.setText(txtId);

        int marginSize =
                (int) context.getResources().getDimension(com.netease.yunxin.kit.conversationkit.ui.R.dimen.fun_add_pop_item_margin_right_top);
        int padding = (int) context.getResources().getDimension(com.netease.yunxin.kit.conversationkit.ui.R.dimen.fun_add_pop_item_padding);
        Drawable drawable = ContextCompat.getDrawable(context, drawableId);
        if (drawable != null) {
            drawable.setBounds(padding, 0, marginSize + padding, marginSize);
            textView.setCompoundDrawables(drawable, null, null, null);
        }
        textView.setPadding(
                (int) context.getResources().getDimension(com.netease.yunxin.kit.conversationkit.ui.R.dimen.dimen_8_dp),
                0,
                (int) context.getResources().getDimension(com.netease.yunxin.kit.conversationkit.ui.R.dimen.dimen_14_dp),
                0);
        textView.setMinWidth((int) context.getResources().getDimension(com.netease.yunxin.kit.conversationkit.ui.R.dimen.fun_add_pop_item_width));
        textView.setTextColor(
                context.getResources().getColor(R.color.color_2e344a));
        textView.setCompoundDrawablePadding(marginSize);
        return textView;
    }



    static LinearLayout.LayoutParams getParams(Context context) {
        return new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                (int) context.getResources().getDimension(com.netease.yunxin.kit.conversationkit.ui.R.dimen.fun_add_pop_item_height));
    }
}
